package io.youngledo.usb.exception;

/// 通用存储浏览器异常基类
/// 继承自`RuntimeException`，不强制调用方处理
///
public class UniversalStorageException extends RuntimeException {

    private final ErrorType errorType;
    private final String errorCode;

    public UniversalStorageException(String message) {
        this(ErrorType.GENERAL, null, message, null);
    }

    public UniversalStorageException(String message, Throwable cause) {
        this(ErrorType.GENERAL, null, message, cause);
    }

    public UniversalStorageException(ErrorType errorType, String message) {
        this(errorType, null, message, null);
    }

    public UniversalStorageException(ErrorType errorType, String errorCode, String message) {
        this(errorType, errorCode, message, null);
    }

    public UniversalStorageException(ErrorType errorType, String errorCode, String message, Throwable cause) {
        super(message, cause);
        this.errorType = errorType;
        this.errorCode = errorCode;
    }

    public ErrorType getErrorType() {
        return errorType;
    }

    public String getErrorCode() {
        return errorCode;
    }

    /**
     * 是否为用户可恢复的错误
     */
    public boolean isRecoverable() {
        return errorType.isRecoverable();
    }

    /**
     * 是否需要重试
     */
    public boolean isRetryable() {
        return errorType.isRetryable();
    }
}